﻿using ParkSaleForAdmin.Data;
using System.Windows;

namespace ParkSaleForAdmin
{
    public class CompanyInfo : IBaseData<CompanyInfo>
    {
        public int ID
        {
            get;
            set;
        }
        public string Name
        {
            get; set;
        }
        public string About
        {
            get;
            set;
        }
        public string Phone
        {
            get;
            set;
        }
        public string Email
        {
            get;
            set;
        }
        public string Type
        {
            get;
            set;
        }
        public CompanyInfo()
        {

        }
        public CompanyInfo(DatabaseData data)
        {

        }

        public CompanyInfo Parse(DatabaseData data)
        {
            ID = int.Parse(data["id"].Value);
            Name = data["name"].Value;
            About = data["about"].Value;
            Phone = data["phone"].Value;
            Email = data["email"].Value;
            Type = data["type"].Value;
            return this;
        }
    }

    /// <summary>
    /// CompanyManagement.xaml 的交互逻辑
    /// </summary>
    public class CompanyManagement : BasicManagerWindow<CompanyInfo>
    {

        public override string TableName => "Company";

        protected override int StandAppendArgsCount => 12;

        protected override string[] values => new string[] { "id", "name", "about", "phone", "email", "type" };

        protected override string[] titles => new string[] { "ID", "企业名", "企业介绍", "联系电话", "电子邮件", "企业类型 1开发商 2承包商 0其他" };

        protected override string[] BindingName => new string[] { "ID", "Name", "About", "Phone", "Email", "Type" };

        protected override string[] InputBoxTitle => new string[] { "企业名", "企业介绍", "联系电话", "电子邮件", "企业类型 1开发商 2承包商 0其他" };

        protected override string[] InputBoxValue => new string[] { "name", "about", "phone", "email", "type" };

        public CompanyManagement()
        {

            BeginToCreate();
            Title = "企业管理";
        }

        protected override bool EachArgForAppend(string n, string value)
        {

            if (value.Length == 0 && !n.Equals("id"))
            {
                MessageBox.Show("空输入错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
            if (n.Equals("type"))
            {
                try
                {
                    int t = int.Parse(value);
                    if (t >= 0 && t <= 2)
                    {
                        return true;
                    }
                    else
                    {
                        MessageBox.Show("输入范围错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }
                }
                catch
                {
                    MessageBox.Show("类型输入错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
            }
            else
            {
                return true;
            }
        }

        public override string DeleteStr(CompanyInfo obj)
        {
            return $"select * from {TableName} where id = {obj.ID}";
        }

        public override string AppendStr(CompanyInfo obj)
        {
            return $"select * from {TableName} where id=99999";
        }

        public override string ChangeStr(CompanyInfo obj)
        {
            return $"select * from {TableName} where id = {obj.ID}";
        }



    }
}
